import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;


public class BlinkNotifier
{
	Font font = null;
	private String msg = "Please Look away, focus on a far away object, and Blink!";

	public BlinkNotifier()
	{
        font = new Font("Roman", Font.PLAIN, 24);
        
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        if (gs.isFullScreenSupported()) {
            System.out.println("Full-screen mode is supported");
        } else {
        	System.out.println("Full-screen mode will be simulated");
        }
	}
	
	public void tellThemToBlink(long timeToShowNotification)
	{
		GraphicsDevice gd = null;
		Frame frame = null;
		GraphicsEnvironment ge = null;
		GraphicsConfiguration gc = null;
		Graphics g = null;
		int height;
		int width;

		try
		{
			ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	        gd = ge.getDefaultScreenDevice();
	        gc = gd.getDefaultConfiguration();
	
	        height = gd.getDisplayMode().getHeight();
	        width = gd.getDisplayMode().getWidth();
	
	        frame = new Frame(gc);
	        frame.setUndecorated(true);
	        frame.setResizable(false);
	        
	        gd.setFullScreenWindow(frame);	// JAVA FULL SCREEN API
	        frame.setIgnoreRepaint(true);
	        
	        int divisor = 20;
	        
	        
	        // active rendering loop since normal swing/awt paint events from OS aren't being used
	            while (divisor-- > 0) {
	                g = frame.getGraphics();
	                // Draw as appropriate using myGraphics
	    	        
	    	        g.setColor(Color.BLACK);
	    	        g.fillRect(0, 0, width, height);
	    	        g.setColor(Color.WHITE);
	    	        g.setFont(font);
	    	        g.drawString(msg, width/2, height/2);

	    	        try
	    	        {
	    	        	Thread.sleep(timeToShowNotification/20);
	    	        }catch (InterruptedException ie)
	    	        {
	    	        	;
	    	        }
	    	        
	                g.dispose();
	            }

	 	}
        finally
        {
        	if(frame != null) { frame.setVisible(false); }
        	if(gd.getFullScreenWindow() != null) { gd.setFullScreenWindow(null); }
        	if(frame != null) { frame.dispose(); }
        }
	}
	
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
